package com.teziyou.commodity;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;
import com.teziyou.commodity.model.AdvicedSSCat;
import com.teziyou.commodity.model.Area;
import com.teziyou.commodity.model.Dict;
import com.teziyou.commodity.model.Distributor;
import com.teziyou.commodity.model.OnSaleTicket;
import com.teziyou.commodity.model.ScenicSpot;
import com.teziyou.commodity.model.Ticket;
import com.teziyou.commodity.web.jfinal.AdvicedSSCatAction;
import com.teziyou.commodity.web.jfinal.DistributorAction;
import com.teziyou.commodity.web.jfinal.IndexAction;
import com.teziyou.commodity.web.jfinal.OnSaleTicketAction;
import com.teziyou.commodity.web.jfinal.ScenicSpotAction;
import com.teziyou.commodity.web.jfinal.TicketAction;

public class CommodityWeb extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		me.setBaseViewPath("/WEB-INF/jsp");
		me.setDevMode(true);
		me.setEncoding("utf-8");
		me.setViewType(ViewType.JSP);
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/", IndexAction.class);
		me.add("/distributor", DistributorAction.class);
		me.add("/scene", ScenicSpotAction.class);
		me.add("/ticket", TicketAction.class);
		me.add("/onsaleTicket", OnSaleTicketAction.class);
		me.add("/advicedSSCat", AdvicedSSCatAction.class);
	}

	@Override
	public void configPlugin(Plugins me) {
		super.loadPropertyFile("jdbc.properties");
		
		String commodityUrl = super.getProperty("commodity.url");
		String commodityUsername = super.getProperty("commodity.user");
		String commodityPassword = super.getProperty("commodity.password");
		DruidPlugin commodityDp = new DruidPlugin(commodityUrl, commodityUsername, commodityPassword);
		ActiveRecordPlugin commodityArp = new ActiveRecordPlugin("commodity", commodityDp);
		me.add(commodityDp);
		commodityArp.setDevMode(true);
		commodityArp.setShowSql(true);
		me.add(commodityArp);
		commodityArp.addMapping("distributor", "distributor_id", Distributor.class);
		commodityArp.addMapping("ticket_info", "ticket_info_id", Ticket.class);
		commodityArp.addMapping("on_sale_ticket", "on_sale_id", OnSaleTicket.class);
		commodityArp.addMapping("scenic_spot", "scenic_id", ScenicSpot.class);
		commodityArp.addMapping("adviced_scenicspot_category", "advicedspot_category_id", AdvicedSSCat.class);
//		commodityArp.addMapping("scenic_comments", "comment_id", ScenicComment.class);
		
		String commonUrl = super.getProperty("common.url");
		String commonUsername = super.getProperty("common.user");
		String commonPassword = super.getProperty("common.password");
		DruidPlugin commonDp = new DruidPlugin(commonUrl, commonUsername, commonPassword);
		ActiveRecordPlugin commonArp = new ActiveRecordPlugin("common", commonDp);
		me.add(commonDp);
		commonArp.setDevMode(true);
		commonArp.setShowSql(true);
		me.add(commonArp);
		commonArp.addMapping("dictionary_definition", "DictionaryId", Dict.class);
		commonArp.addMapping("administrativedivision", "adm_div_id", Area.class);
		
		String memberUrl = super.getProperty("member.url");
		String memberUsername = super.getProperty("member.user");
		String memberPassword = super.getProperty("member.password");
		DruidPlugin memberDp = new DruidPlugin(memberUrl, memberUsername, memberPassword);
		ActiveRecordPlugin memberArp = new ActiveRecordPlugin("member", memberDp);
		me.add(memberDp);
		memberArp.setDevMode(true);
		memberArp.setShowSql(true);
		me.add(memberArp);
//		memberArp.addMapping("our_members", "Id", Member.class);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		
	}

	@Override
	public void configHandler(Handlers me) {
		
	}

}
